package com.zpf.service.impl;

import com.zpf.dao.GoodsDao;
import com.zpf.dao.impl.GoodsDaoImpl;
import com.zpf.pojo.Goods;
import com.zpf.pojo.GoodsType;
import com.zpf.pojo.PageBean;
import com.zpf.service.GoodsService;
import com.zpf.service.GoodsTypeService;

import java.util.List;

public class GoodServiceImpl implements GoodsService {
    GoodsDao goodsDao = new GoodsDaoImpl();

    @Override
    public PageBean findbypage(int typeId, int pageNum, int pageSize) {
       PageBean pageBean = new PageBean();
        pageBean.setPageNum(pageNum);
        pageBean.setPageSize(pageSize);
        //查询总条数
        long totalCount = goodsDao.findtotalCount(typeId);
        pageBean.setTotalCount(totalCount);
        //limit m,n m:其实索引 n:每页条数
        List<Goods> list = goodsDao.findData(typeId,(pageNum-1)*pageSize,pageSize);
        pageBean.setData(list);



        return pageBean;
    }

    @Override
    public Goods findById(int id) {
        Goods goods = goodsDao.findById(id);
        //查询商品分类信息，存储到商品对象中
        GoodsTypeService typeService = new GoodsTypeServiceImpl();
        // 根据商品分类，查询分类信息
          GoodsType goodsType= typeService.findById(goods.getTypeid());
        //存储到商品对象中
        goods.setGoodsType(goodsType);

        return goods;
    }
}
